package com.share.algorithm.sort;

/**
 * @desc:  冒泡排序
 * @author:caifan
 * @date:2020/9/24
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arrays = new int[]{3, 9, 8, 2, 7};
        bubbleSort(arrays);
        for (int i=0;i<arrays.length;i++) {
            System.out.println(arrays[i]);
        }
    }

    public static int[] bubbleSort(int[] array) {
        for (int i=0;i<array.length;i++) {
            for (int j=0;j<array.length - i -1;j++) {
                if (array[j] > array[j+1]) {
                    int temp;
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
            System.out.println(array);
        }
        return array;
    }
}
